﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HandyControl.Tools.Extension;
using MachineVision.Core.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MachineVision.Core
{
    /// <summary>
    /// 对话框返回ViewModel
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial class DialogViewModel<T> : ObservableObject, IDialogResultable<ResponseResult<T>>
    {
        /// <summary>
        /// 返回结果
        /// </summary>
        public ResponseResult<T> ConfirmResult = ResponseResult<T>.Error();

        /// <summary>
        /// 结果
        /// </summary>
        public ResponseResult<T> Result { 
            get 
            { 
                return ConfirmResult; 
            } 
            set 
            { 
                ConfirmResult = value; 
            } 
        }
        
        /// <summary>
        /// 关闭程序指令
        /// </summary>
        public Action CloseAction { get; set; }


        /// <summary>
        /// 确定
        /// </summary>
        [RelayCommand]
        private void Confirm()
        {
            ConfirmResult = ResponseResult<T>.Success();
            CloseAction?.Invoke();
        }

        /// <summary>
        /// 取消
        /// </summary>
        [RelayCommand]
        private void Cancel()
        {
            ConfirmResult = ResponseResult<T>.Error();
            CloseAction?.Invoke();
        }
    }
}
